<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use App\Models\Configs;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class ConfigController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        // $type = request('type', 'basic');
        $items = Configs::pluck('value', 'key');
        return $this->successful($items);
    }

    /**
     * @param  Request  $request
     */
    public function store(Request $request)
    {
        $data = $request->post();
        foreach ($data as $key => $value) {
            Configs::where('key', $key)->update(['value' => $value]);
        }
        Cache::forget('cache:configs');
        return $this->successful(true);
    }
}
